"""
已经创建好了excel表格，表名为login.xlsx，sheet名为login
"""
from openpyxl import load_workbook


class ReadExcel:
    def __init__(self, sheetName):
        self.wb = load_workbook(login.xlsx)  # 将excel表加载到内存，打开excel表格
        self.sh = self.wb[sheetName]

    def getRowValue(self, rowNo):
        """
        获取某一行的数据
        """
        rowValueList = []      # 将拿到的数据放在这个空列表里面
        for y in range(2, self.sh.max_column+1):
            value = self.sh.cell(rowNo, y).value
            rowValueList.append(value)
        return rowValueList

    def getColValue(self, colNo):
        """
        获取某一列的数据
        """
        colValueList = []
        for x in range(2, self.sh.row_max+1):
            value = self.sh.cell(x, colNo).value
            colValueList.append(value)
        return colValueList

    def getCellValue(self, rowNo, colNo):
        """
        获取某一个单元格的值
        """
        value = self.sh.cell(rowNo, colNo).value
        return value

    def writeValue(self, rowNo, colNo, value):
        """
        往某一个单元格中写入数据
        """
        self.sh.cell(rowNo, colNo).value = value
        self.wb.save(login.xlsx)
        return True


if __name__ == "__main__":
    A = ReadExcel('login.xlsx')
    print(A.writeValue(2, 8, value='big'))

